import { LOGIN_START,LOGIN_SUCCESS,LOGIN_FAIL } from "./actionTypes";
import { userLogin } from "../api/user";
export const loginStart = (payload)=>{
    return {
        type:LOGIN_START,
        payload
    }
}
export const loginSuccess = (payload)=>{
    return {
        type:LOGIN_SUCCESS,
        payload
    }
}
export const loginFail = (payload)=>{
    return {
        type:LOGIN_FAIL,
        payload
    }
}

export const loginAsgnc = (payload,history)=>{
    return (dispatch)=>{
        dispatch(loginStart())
        userLogin(payload).then(res=>{
            let {remember} = payload
            dispatch(loginSuccess({...res.data,remember}))
            history.push('/main')
        }).catch(()=>{
            dispatch(loginFail())
        })
    }
}